#include <a_samp>

#define DIALOG_RADIO 9456

new AudioStream[MAX_PLAYERS];

forward PlayRadioStationForPlayer(playerid, station);

public OnFilterScriptInit()
{
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

main(){}

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[128], id;
	cmd = strtok(cmdtext, id);

	if (strcmp(cmd, "/stereo", true) == 0)
	{
		if(IsPlayerInAnyVehicle(playerid) == 1)
		{
			new tmp[128];
			tmp = strtok(cmdtext, id);
			if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFF330000, "USAGE: /stereo off, /stereo on");
			else if(strcmp(tmp, "off", true) == 0)
			{
				StopAudioStreamForPlayer(playerid);
				AudioStream[playerid] =0;
				return 1;
			}
			else if(strcmp(tmp, "on", true) == 0)
			{
			    ShowPlayerDialog(playerid, DIALOG_RADIO, DIALOG_STYLE_LIST, "{FFFFFF}Los Angeles Radio","{FFFFFF}Dance Hits\nTop 40\nHouse\nClassic Rock\nTrance\nVocal Trance\nGangsta Rap\nHip-Hop\nHoward Stern\nRomanian Classical\nRomanian Dance/Pop\nFilthy Dubstep\nCountry\nSmooth Jazz","Ok","Cancel");
				return 1;
			}
			SendClientMessage(playerid, 0xFF330000, "USAGE: /stereo off, /stereo on");
			return 1;
		}
		else
		{
			SendClientMessage(playerid, 0xFF330000, "SERVER: You need to be in the drivers seat of a vehicle to use this command!");
			return 1;
		}
	}
	return 0;
}

public OnPlayerDisconnect(playerid, reason)
{
	AudioStream[playerid] =0;
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid)
	{
		case DIALOG_RADIO:
		{
			if(!response) return SendClientMessage(playerid, 0xFF330000, "You did not select a station!");
			switch(listitem)
			{
				case 0:
				{
					PlayRadioStationForPlayer(playerid, 1);
					return 1;
				}
				case 1:
				{
					PlayRadioStationForPlayer(playerid, 2);
					return 1;
				}
				case 2:
				{
					PlayRadioStationForPlayer(playerid, 3);
					return 1;
				}
				case 3:
				{
					PlayRadioStationForPlayer(playerid, 4);
					return 1;
				}
				case 4:
				{
					PlayRadioStationForPlayer(playerid, 5);
					return 1;
				}
				case 5:
				{
					PlayRadioStationForPlayer(playerid, 6);
					return 1;
				}
				case 6:
				{
					PlayRadioStationForPlayer(playerid, 7);
					return 1;
				}
				case 7:
				{
					PlayRadioStationForPlayer(playerid, 8);
					return 1;
				}
				case 8:
				{
					PlayRadioStationForPlayer(playerid, 9);
					return 1;
				}
				case 9:
				{
					PlayRadioStationForPlayer(playerid, 10);
					return 1;
				}
				case 10:
				{
					PlayRadioStationForPlayer(playerid, 11);
					return 1;
				}
				case 11:
				{
					PlayRadioStationForPlayer(playerid, 12);
					return 1;
				}
				case 12:
				{
					PlayRadioStationForPlayer(playerid, 13);
					return 1;
				}
				case 13:
				{
				    PlayRadioStationForPlayer(playerid, 14);
				    return 1;
				}
			}
		}
	}
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
	{
	    StopAudioStreamForPlayer(playerid);
	}
	if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT && AudioStream[playerid] != 0)
	{
		PlayRadioStationForPlayer(playerid, AudioStream[playerid]);
	}
	return 1;
}

public PlayRadioStationForPlayer(playerid, station)
{
	switch(station)
	{
	    case 1:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=140547");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Dance Hits");
			AudioStream[playerid] =1;
			return 1;
		}
		case 2:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283896");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Top 40");
			AudioStream[playerid] =2;
			return 1;
		}
		case 3:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1377360");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: House");
			AudioStream[playerid] =3;
			return 1;
		}
		case 4:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=98355");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Classic Rock");
			AudioStream[playerid] =4;
			return 1;
		}
		case 5:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1193516");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Trance");
			AudioStream[playerid] =5;
			return 1;
		}
		case 6:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1177953");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Vocal Trance");
			AudioStream[playerid] =6;
			return 1;
		}
		case 7:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1504548");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Gangsta Rap");
			AudioStream[playerid] =7;
			return 1;
		}
		case 8:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Hip-Hop");
			AudioStream[playerid] =8;
			return 1;
		}
		case 9:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=48482");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Howard Stern");
			AudioStream[playerid] =9;
			return 1;
		}
		case 10:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1753881");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Romanian Classical");
			AudioStream[playerid] =10;
			return 1;
		}
		case 11:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=2083063");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Romanian Dance/Pop");
			AudioStream[playerid] =11;
			return 1;
		}
		case 12:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=118236");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Filthy Dubstep");
			AudioStream[playerid] =12;
			return 1;
		}
		case 13:
		{
			PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=2235429");
			SendClientMessage(playerid, 0xFF330000, "Now Playing: Country");
			AudioStream[playerid] =13;
			return 1;
		}
		case 14:
		{
		    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=496891");
		    SendClientMessage(playerid, 0xFF330000, "Now Playing: Smooth Jazz");
		    AudioStream[playerid] =14;
	    	return 1;
		}
	}
	return 1;
}

strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
